/**
 * 
 */
package com.ccqlk.attendance.config;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.core.annotation.Order;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet;

import com.ccqlk.attendance.config.spirng.SpringConfig;

/**
 * Copyright 2015-2018 重庆鲁控科技有限公司<br>
 * 文件标题: WebConfig<br>
 * 文件说明: TODO<br>
 * @author ZhangYinxian 348893009@qq.com<br>
 * 创建时间 2016年5月26日 下午10:35:13<br>
 */
@Order(0)
public class WebConfig implements WebApplicationInitializer {

	/* (non-Javadoc)
	 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
	 */
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		
		
		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
		applicationContext.register(SpringConfig.class);
		applicationContext.register(SpringMvcConfig.class);
		
		
		
		ServletRegistration.Dynamic springmvcDispatcher = servletContext.addServlet("attendance", new DispatcherServlet(applicationContext));
		springmvcDispatcher.setLoadOnStartup(1);
		springmvcDispatcher.addMapping("*.jspx");
		springmvcDispatcher.addMapping("*.json");
		
		FilterRegistration.Dynamic charactorFilter = servletContext.addFilter("characterEncoding", new CharacterEncodingFilter("utf-8", true));
		charactorFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

	}

}
